/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.admin;

import java.util.*;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import model.*;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "emb")
@SessionScoped
public class EmployeeManagedBean {
    @EJB
    private DepartmentFacade departmentFacade;
    
    @EJB
    private EmployeeFacade employeeFacade;
    private Employee em = new Employee();
    private String DepartmentID;
private String message = new String();

    public String getMessage() {
        return message;
    }
    public String getDepartmentID() {
        return DepartmentID;
    }

    public void setDepartmentID(String DepartmentID) {
        this.DepartmentID = DepartmentID;
    }

    public EmployeeFacade getEmployeeFacade() {
        return employeeFacade;
    }

    public void setEmployeeFacade(EmployeeFacade employeeFacade) {
        this.employeeFacade = employeeFacade;
    }

    public Employee getEm() {
        return em;
    }

    public void setEm(Employee em) {
        this.em = em;
    }

   
    public EmployeeManagedBean() {
    }
    public List<Employee> employeeList(){
        return this.employeeFacade.findAll();
        
    }
    public String createemloyee()
    {             
            this.em.setDepartmentID(this.departmentFacade.find(this.DepartmentID));
        this.employeeFacade.create(em);        
       
        return "List";
    }
    
    public String editem(){
        this.employeeFacade.edit(this.em);
        return "List";
    }
    public String emEdit(Employee e){
        this.em = e;
        return "Edit";
    }
    
    public String emView(Employee e){
        this.em = e;
        return "View";
    }
    public String deleteemployee(Employee e){
        String page = "";
        try {
            this.employeeFacade.remove(e);
            page="List";
        }catch(Exception ex) {
            this.message ="Delete not found";
        }
        return page;
    }
 
}
